package morenoapp.components.common.table.renderer;

import java.awt.Component;
import java.awt.Graphics;
import java.util.List;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import morenoapp.MorenoApp;
import morenoapp.model.data.MorenoRespondentFace;

/**
 *
 * @author dmitry.mamonov
 */
public class RespondentProxyPanelTableCellRenderer extends ProxyPanelTableCellRenderer {
    protected boolean drawGrayBackground = false;

    public RespondentProxyPanelTableCellRenderer(TableCellRenderer delegate) {
        super(delegate);
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        List<MorenoRespondentFace> respondents = MorenoApp.getModel().getRespondentsList();
        if (respondents.size() > row) {
            MorenoRespondentFace resp = respondents.get(row);
            drawGrayBackground = resp.isPassedPoll();
        } else {
            drawGrayBackground = false;
        }
        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }

    @Override
    protected void paintBackground(Graphics g) {
        if (drawGrayBackground) {
            super.paintBackground(g);
        }
    }
}
